import Scaner from './Scaner.js'
import NestTokens from './NestTokens.js'


/* 
      将模版字符串转换成tokens。
*/
export default function parseTemplateToTokens(templateStr) {
      var tokens = [];

      var scaner = new Scaner(templateStr)
      var word;
      while (!scaner.eos()) {
            word = scaner.scanUtil('{{')
            if (word) {
                  tokens.push(['text', word]);
            }
            scaner.scan('{{');

            word = scaner.scanUtil('}}')
            if (word) {
                  if (word[0] == '#') {
                        tokens.push(['#', word.substring(1)]);
                  } else if (word[0] == '/') {
                        tokens.push(['/', word.substring(1)]);
                  } else {
                        tokens.push(['name', word]);
                  }
            }
            scaner.scan('}}');
      }

      // 发回折叠收集的tokens
      return NestTokens(tokens);
      // return tokens;
}